from re_common.baselibrary.utils.core.mdeprecated import try_except2, try_except2_async

from apps.crawler_platform.core_abs.downstepabs import ParaItems
from apps.crawler_platform.core_callback import null
from apps.crawler_platform.core_callback.err_callback import all_client_back_callback
from apps.crawler_platform.core_platform.base_down import BaseDown
from apps.crawler_platform.core_platform.core_controller import CoreConterollerMixin

STATICA_HACK = False
# globals()['kcah_acitats'[::-1].upper()] = False
if STATICA_HACK:  # pragma: no cover
    null()


class BaseOtherItems(ParaItems):

    def __init__(self):
        super(BaseOtherItems, self).__init__()
        self.list_rawid: str = ''


class BaseOtherStep(BaseDown, CoreConterollerMixin):

    def __init__(self):
        super().__init__()
        # 请继承类设置该参数
        self.task_table = ""

    def set_table(self, *args, **kwargs):
        """
        处理 self.task_table 在不同任务不同表的情况
        :return:  self.task_table
        """
        raise NotImplementedError("必须重写该方法设置self.task_table 变量 .")

    async def my_task(self, table=""):
        """
        接入调用的task
        ZCN:函数内部有逻辑,因此返回的上层的布尔值
        :return:
        """
        return await super().my_task(self.task_table)

    @try_except2()
    def verify_html(self):
        """
        验证html
        """
        # 如果验证规则存在 在这里进行验证逻辑
        return True, ""

    @try_except2()
    def verify_para(self):
        """
        验证解析出来的数据
        """
        return True, {}

    @try_except2_async(callback=all_client_back_callback, is_print=True)
    async def run_task(self):
        bools, err_info = await self.task_step()
        # 获取最终结果
        return bools, err_info
